package com.gukun.springboot.tdengine.enums;

import lombok.Data;
import lombok.Getter;

import java.math.BigInteger;
import java.sql.Timestamp;

/**
 * @author zhang
 */

@Getter
public enum TdengineDataType {
    TIMESTAMP("TIMESTAMP", false, "时间戳", false,false, Timestamp.class,"long"),
    INT("INT", false, "整型", false,true,Integer.class,"int"),
    INT_UNSIGNED("INT UNSIGNED", false, "无符号整型", false,true,Long.class,"long"),
    BIGINT("BIGINT", false, "长整型", false,true,Long.class,"long"),
    BIGINT_UNSIGNED("BIGINT UNSIGNED", false, "无符号长整型", false,true, BigInteger.class,"long"),
    FLOAT("FLOAT", false, "浮点型", false,true,Float.class,"float"),
    DOUBLE("DOUBLE", false, "双精度浮点型", false,true,Double.class,"double"),
    SMALLINT("SMALLINT", false, "短整型", false,true,Short.class,"int"),
    SMALLINT_UNSIGNED("SMALLINT UNSIGNED", false, "无符号短整型", false,true,Integer.class,"int"),
    TINYINT("TINYINT", false, "单字节整型", false,true,Byte.class,"int"),
    TINYINT_UNSIGNED("TINYINT UNSIGNED", false, "无符号单字节整型", false,true,Short.class,"int"),
    BOOL("BOOL", false, "布尔型", false,false,Boolean.class,"boolean"),
    JSON("JSON", false, "JSON数据类型", true,false,String.class,"string"),
    NCHAR("NCHAR", true, "字符串", false,false,String.class,"string"),
    VARCHAR("VARCHAR", true, "字符串", false,false,String.class,"string"),
    GEOMETRY("GEOMETRY", false, "几何类型", false,false,String.class,"string"),
    VARBINARY("VARBINARY", true, "可变长的二进制类型", false,false,String.class,"string"),;


    /**
     * 类型名称
     */
    private final String name;
    /**
     * 长度
     */
    private final boolean length;
    /**
     * 描述
     */
    private final String desc;
    /**
     * 是否为标签特有类型
     */
    private final boolean tag;
    /**
     * 是否为数字类型
     */
    private final boolean isNumber;
    /**
     * 数据类相关对应Java中的类
     */
    private final Class<?> className;

    /**
     * avro文件中对应的类型
     */
    private final String avroType;

    TdengineDataType(String name, boolean length, String desc, boolean tag,boolean isNumber,Class className,String avroType) {
        this.name = name;
        this.length = length;
        this.desc = desc;
        this.tag = tag;
        this.isNumber = isNumber;
        this.className = className;
        this.avroType = avroType;
    }

    /**
     * 通过类型名称获取枚举类
     * @param name 类型名称
     * @return
     */
    public static TdengineDataType getTdengineDataType(String name) {
        for (TdengineDataType type : TdengineDataType.values()) {
            if (type.name.equalsIgnoreCase(name)) {
                return type;
            }
        }
        return null;
    }
}
